package com.teichmann.core.targets.online.revolution;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.teichmann.bo.Car;
import com.teichmann.core.Page;
import com.teichmann.services.CarServices;

public class CarSearch {

	private ArrayList<Car> returnedCars;
	private Page[] pages;
	private BasicPage[] onlinePages;

	public CarSearch(List<Page> pages) {
		this.pages = pages.toArray(new Page[0]);
	}

	public CarSearch(Page[] pages) {
		this.pages = pages;
	}

	public CarSearch(ArrayList<BasicPage> onlinePages) {
		this.onlinePages = onlinePages.toArray(new BasicPage[0]);
	}

	public CarSearch(BasicPage[] pages) {
		this.onlinePages = pages;
	}

	public void process(String parameter) throws IOException {

		for (BasicPage p : onlinePages) {
			  p.performSearch(parameter);
		}
		// CarServices.updateFoundCars(returnedCars);

	}

	public void process() throws IOException {
		returnedCars = new ArrayList<Car>();
		for (Page p : pages) {
			returnedCars.addAll(p.performSearch());
		}

		CarServices.updateFoundCars(returnedCars);

	}

}
